﻿using MotorLibrary.Repository.DTO;
using MotorLibrary.Service;
using System.Collections.Generic;
using System.Web.Http;

namespace WebMotor.Controllers
{
    public class EndpointController: ApiController, IEndpointController
    {
        private IEndpointService _endpointService;
        public EndpointController(IEndpointService endpointService)
        {
            this._endpointService = endpointService;
        }
        
        // GET api/endpoint
        [HttpGet]
        [Route("api/endpoint")]
        public IList<EndpointDTO> Get()
        {
            return _endpointService.FilterActivos();
        }

        // GET api/endpoint/{id}
        [HttpGet]
        [Route("api/endpoint/{id}")]
        public EndpointDTO Get(long id)
        {
            return _endpointService.Read(id);
        }

        // POST api/endpoint
        [HttpPost]
        [Route("api/endpoint")]
        public EndpointDTO Post(EndpointDTO dto)
        {
            return _endpointService.Create(dto);
        }

        // PUT api/endpoint/{id}
        [HttpPut]
        [Route("api/endpoint/{id}")]
        public EndpointDTO Put(long id, EndpointDTO dto)
        {
            return _endpointService.Update(dto);
        }

        // DELETE api/endpoint/{id}
        [HttpDelete]
        [Route("api/endpoint/{id}")]
        public EndpointDTO Delete(long id)
        {
            return _endpointService.Delete(id);
        }

        // GET api/endpoint/tipo/{idTipo}
        [HttpGet]
        [Route("api/endpoint/tipo/{tipoID}")]
        public IList<EndpointDTO> FilterByTipo(long tipoID)
        {
            return _endpointService.FilterByTipo(tipoID);
        }
    }
}